# @Author：silence
# @Email：792245022@qq.com
# @Date：2025/3/1 14:03

import os
import time

record_log_path = "E:/Workspaces/IO_Test/record-log.txt"

def operation_menu():
    print()
    print("请选择操作".center(50, "="))
    print("\t\t\t\t1 查 看 当 前 登 录 用 户")
    print("\t\t\t\t2 查 看 登 录 日 志")
    print("\t\t\t\t3 退 出 系 统")

def record_log(user: str, info: str):
    """
    记录登录日志
    :param user: 当前登录用户名
    :param info: 登录成功还是失败
    :return:
    """
    with open(record_log_path, "a", encoding="utf-8") as f:
        f.write(f"登录用户：{user}, {info} 登录时间：{time.strftime('%Y-%m-%d %H:%M:%S')}\n")

def read_log():
    if not os.path.exists(record_log_path):
        with open(record_log_path, "a", encoding="utf-8") as f:
            ...
    with open(record_log_path, "r", encoding="utf-8") as f:
        for line in f:
            print(line, end="")

if __name__ == "__main__":
    user = input("请输入你的用户名：")
    pwd = input("请输入你的密码：")

    if user in ["smith", "tom", "hsp"] and pwd == "888":
        record_log(user, "登录成功")
        while True:
            operation_menu()
            key = input("请输入你的选择：")

            if key == "1":
                print(f"当前登录用户是：{user}")
            elif key == "2":
                read_log()
            elif key == "3":
                print("退出系统...")
                break
            else:
                print("你的选择有误，请重新选择")
    else:
        record_log(user, "登录失败")
        print("用户名/密码有误，重新登录")



